--[[
	处理使用道具
]]
local filename = "relive.lua"

local timetool = require "timetool"
local skynet = require "skynet"
local cluster = require "skynet.cluster"
local filelog =require "filelog"
local redisdao = require "redisdao"
require "pubenum"

local json = require "cjson"
json.encode_sparse_array(true,1,1)


local service = nil
local CMD = {
	service = nil
}

--小游戏列表
-- dds 打地鼠 dfj 打飞机 llk连连看
local gamelist = { dds = true, dfj = true, llk = true}

--
--小游戏复活
--
function CMD.process(rid, msgbody)
	if not service then
		service = CMD.service
	end

    if not msgbody or not gamelist[msgbody.gamename] then
        return {retcode = EErrCode.ERR_INVALID_PARAMS, retstr = "无效的参数"}
    end
   
    --扣费,扣10个金豆
    local value = -10
    local beginvalue = service.money.diamond
    local setargs = service:change_money({diamond = value})
    if setargs then
        --记录日志
        local logstr = nil

        local comment = { }
        local now = timetool.get_time()
        comment.tradeid = skynet.call(".nodeuuid", "lua", "getuuid")
        comment.table_uuid = msgbody.gamename .. "node" .. "_" .. 0 .. "_" .. 0 .. "_" .. now
        logstr = string.format("%d,%d,%d,%d,%d,%d,%d,%d,%d,%s,%s,%s", EDiamondChange.RELIVE, rid, service.info.level, value, 0, 0, beginvalue, service.money.diamond, service.money.lock_diamond, comment.table_uuid, now, comment.tradeid)
        skynet.send(".diamondlog", "lua", "write_file_redis", logstr, rid)
        return {gamename = msgbody.gamename}
    end

    return {retcode = EErrCode.ERR_INVALID_REQUEST, retstr = "复活失败"}
end

return CMD
